<template>
  <div class="article-lists">
    <el-card class="!border-none" shadow="never">
      <el-form ref="formRef" :inline="true" :model="queryParams" class="mb-[-16px]">
        <el-form-item label="企业名称">
          <el-input
            v-model="queryParams.title"
            class="w-[280px]"
            clearable
            @keyup.enter="resetPage"
          />
        </el-form-item>


        <el-form-item>
          <el-button type="primary" @click="resetPage">查询</el-button>
          <el-button @click="resetParams">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="!border-none mt-4" shadow="never">
      <div>
        <router-link
          v-perms="['enterprise.enterprise']"
          :to="{
                        path: getRoutePath('enterprise.enterprise')
                    }"
        >
          <el-button class="mb-4" type="primary">
            <template #icon>
              <icon name="el-icon-Plus" />
            </template>
            新增企业
          </el-button>
        </router-link>
      </div>
      <el-table :data="formdata.data" size="large">
        <el-table-column label="ID" min-width="80" prop="id" />
        <el-table-column label="企业商标" min-width="100">
          <template #default="{ row }">
            <image-contain
              v-if="row.trademark"
              :height="45"
              :preview-src-list="[row.trademark]"
              :src="row.trademark"
              :width="60"
              fit="contain"
              preview-teleported
            />
          </template>
        </el-table-column>
        <el-table-column
          label="企业介绍"
          min-width="160"
          prop="introduce"
          show-tooltip-when-overflow
        />
        <el-table-column label="企业联系人" min-width="100" prop="contacts" />
        <el-table-column label="企业名称" min-width="120" prop="name" />
        <!--        <el-table-column label="浏览量" prop="click" min-width="100" />-->
        <!--        <el-table-column label="状态" min-width="100">
                  <template #default="{ row }">
                    <el-switch
                      v-perms="['article.article/updateStatus']"
                      v-model="row.is_show"
                      :active-value="1"
                      :inactive-value="0"
                      @change="changeStatus($event, row.id)"
                    />
                  </template>
                </el-table-column>-->
        <el-table-column label="排序" min-width="100" prop="sort" />
        <!--        <el-table-column label="发布时间" prop="create_time" min-width="120" />-->
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button
              v-perms="[ 'enterprise.enterprise']"
              type="primary"
              link
            >
              <router-link
                :to="{
                                    path: getRoutePath('enterprise.enterprise'),
                                    query: {
                                        id: row.id
                                    }
                                }"
              >
                编辑
              </router-link>
            </el-button>
            <el-button
              v-perms="['article.article/delete']"
              type="danger"
              link
              @click="handleDelete(row.id)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex justify-end mt-4">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          @next-click="xiayiye"
          :current-page="pagefen.page_no"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pagefen.page_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagefen.total">
        </el-pagination>
        <!--        <pagination v-model="pager" @change="getLists" />-->
      </div>
    </el-card>
  </div>
</template>
<script lang="ts" name="articleLists" setup>
import { articleCateAll, enterpriseDelete, enterpriselist } from "@/api/article";
import { useDictOptions } from "@/hooks/useDictOptions";
import { usePaging } from "@/hooks/usePaging";
import { getRoutePath } from "@/router";
import { onMounted } from "vue";
import feedback from "@/utils/feedback";

const queryParams = reactive({
  title: "",
  cid: "",
  is_show: ""
});
const formdata = reactive({
  data: ""
});

const pagefen = reactive({
  page_no: "",
  page_size:10,
  total:""
});
/*const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: enterpriselist,
  params: queryParams
});*/
const xiayiye=()=>{
  console.log(pagefen.page_no);
}
const  handleCurrentChange=(e)=>{
  pagefen.page_no=e
  enterpriselist({
    page_no:pagefen.page_no,
    page_size:pagefen.page_size,
    name:queryParams.title
  }).then((res)=>{
    formdata.data = res.data;
    pagefen.total=res.shuliang
    pagefen.page_no=e
  })
}
const resetPage=()=>{
  enterpriselist({name:queryParams.title,
    page_no:pagefen.page_no,
    page_size:pagefen.page_size
  }).then((res)=>{
      formdata.data = res.data;
      pagefen.total=res.shuliang
    }

  )
}
const { optionsData } = useDictOptions<{
  article_cate: any[]
}>({
  article_cate: {
    api: articleCateAll
  }
});


onActivated(() => {

});
const handleDelete = async (id: number) => {
  await feedback.confirm('确定要删除？')
  await enterpriseDelete({ id:id })
  pagefen.page_no=1
  enterpriselist({
    page_no:pagefen.page_no,
    page_size:pagefen.page_size,
    name:queryParams.title
  }).then((res)=>{
    formdata.data = res.data;
    pagefen.total=res.total
  })
}
onMounted(() => {
  pagefen.page_no=1
  enterpriselist({
    page_no:pagefen.page_no,
    page_size:pagefen.page_size,
    name:queryParams.title
  }).then((res)=>{
    formdata.data = res.data;
    pagefen.total=res.shuliang
  })
  // 在这里执行与 onLoad 类似的操作
});

</script>
